package com.example.anliku.timetask;

import com.example.anliku.service.ElasticSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author ClayeLink
 * @date 2021/2/23 19:10
 */
@Configuration
@EnableScheduling
@Slf4j
public class RedisScheduleTask {

    @Resource
    private ElasticSearchService elasticSearchService;

    /**
     * 定时任务 Redis下载量与ES同步
     *  每天晚上12点 更新 数据
     */
    @Scheduled(cron = "0 0 0 1/1 * ?")
    private void downloadRTE() {
        boolean isOK = elasticSearchService.blukUpadteForRedis();
        log.info("定时任务: "+ LocalDateTime.now() + " Redis下载量与ES同步操作");
        if(isOK){
            log.info("定时任务: "+ LocalDateTime.now() + " RTE数据同步成功");
        }else{
            log.error("定时任务: "+ LocalDateTime.now() + " RTE数据同步失败");
        }
    }

}
